﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Subscriber
{
    [Serializable]
    public class UltAction
    {
        /// <summary>
        /// 根据流程名、实例号 获取主流程taskid
        /// </summary>
        /// <param name="strProcessName"></param>
        /// <param name="nIncident"></param>
        /// <param name="cls"></param>
        /// <returns></returns>
        public static string GetMainTaskid(string strProcessName, int nIncident,clsOleDB cls)
        {
            string strSql = "  select PARENTTASKID from ULTIMUSDB..INCIDENTS " +
                                " where INCIDENT ='" + nIncident + "' and PROCESSNAME='" + strProcessName + "'";
           // cls.wteLog("", false, strSql);
            DataTable dt = cls.getDtRtn(strSql);
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0][0].ToString();
            }
            return null;
        }

        public static string UpdateStatus(string strProcessName, int incident, int status, clsOleDB cls)
        {
            string strSql = "  select EXT01 from COM_RESOURCE " +
                                " where CNNAME='" + strProcessName + "' and type='PROCESS' ";
            // cls.wteLog("", false, strSql);
            DataTable dt = cls.getDtRtn(strSql);
            if (dt.Rows.Count > 0)
            {
                string tablename= dt.Rows[0][0].ToString();
                if (!string.IsNullOrEmpty(tablename))
                {
                    string Query1 = "update " + tablename + " set status =" + status + "  where processname='" + strProcessName.Trim() + "' and incident =" + incident;
                    cls.exeSql(Query1);
                    return "更新表"+tablename+"状态成功";
                }
            }
            return "";
        }

        /// <summary>
        /// 是否存在指派
        /// </summary>
        /// <param name="strProcessName"></param>
        /// <param name="strTskUser"></param>
        /// <param name="strTskAssignUser"></param>
        /// <param name="cls"></param>
        /// <returns></returns>
        public static bool isExistAssign(string strProcessName, string strTskUser,ref string strTskAssignUser, clsOleDB cls)
        {
            bool isExistAssign = false;
            string strSql = "select * from WF_ASSIGNMENT where (GETDATE() between BgDate and EdDate) " +
                                         " and TskUser='"+strTskUser+"' and ProcessName like '%"+strProcessName+"%' and IsEnable = 1";
          //  string.Format(strSql, strTskUser, strProcessName);
            DataTable dt = cls.getDtRtn(strSql);

            if (dt.Rows.Count > 0)
            {
                isExistAssign = true;
                //返回代理人
              //  cls.wteLog("", false, "返回代理人" + strTskAssignUser);
                strTskAssignUser = dt.Rows[0]["TskAssignUser"].ToString();
             //   cls.wteLog("", false, "返回代理人" + strTskAssignUser);
            }
            return isExistAssign;
        }
    }
}
